/**
 * 
 */
package connection;

import java.io.InputStream;
import java.sql.Connection;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;



/**
 * @author Liulianqiu
 *2020年7月17日
 */
public class Jdbc01 {

	public static void main(String []arg) throws Exception {
		testConnetion();
	}
	
	    static void testConnetion() throws Exception {
//		获取驱动实现类对象(第一种方式)
//		Driver driver = new com.mysql.jdbc.Driver() ;
//	    (第二种方式)
//	    Class clazz = Class.forName("com.mysql.jdbc.Driver");
//	    Driver driver = (Driver) clazz.newInstance();
//	    
////		给出数据库所在的路径
//		String url = "jdbc:mysql://localhost:3306/llq";
////		给出用户名和密码
////		Properties info = new Properties();
////		info.setProperty("user", "root");
////		info.setProperty("password","2000");
////		最终获取连接(即获得一个女生的联系方式)
//		Connection conn = driver.connect(url,info);
//		System.out.println(conn);
		
//		第三种方式:使用DriverManager驱动管理器来替换Driver驱动器
//		Class clazz = Class.forName("com.mysql.jdbc.Driver");
//	    Driver driver = (Driver) clazz.newInstance();
////	       注册驱动
//		DriverManager.registerDriver(driver);
//		String url = "jdbc:mysql://localhost:3306/llq";
//		String user = "root";
//		String password = "2000";
//		Connection conn = DriverManager.getConnection(url, user, password);
//		System.out.println(conn);
	    	
	    	
//	   第四种方式
//	    	String url = "jdbc:mysql://localhost:3306/llq";
//	    	String user = "root";
//	    	String password = "2000";
//	    	Class.forName("com.mysql.jdbc.Driver");
////		       注册驱动
////			DriverManager.registerDriver(driver);
//			Connection conn = DriverManager.getConnection(url, user, password);
//			System.out.println(conn);
	    	
//	    第五种方式
	    	
//		       注册驱动
//			DriverManager.registerDriver(driver);
	    	InputStream in = ClassLoader.getSystemClassLoader().getResourceAsStream("db.properties");
	    	Properties pro = new Properties();
	    	pro.load(in);
	    	
	    	String url = pro.getProperty("url");
	    	String password = pro.getProperty("password");
	    	String user = pro.getProperty("user");
	    	String driveClass = pro.getProperty("driveClass");
	    	
	    	Class.forName(driveClass);
			Connection conn = DriverManager.getConnection(url, user, password);
			System.out.println(conn);
	    	
	}
}
